<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

require_once ADMIN.DS."/head.php";
?>
<h1>Разделы</h1><?php
	if ($route->GET("order") == "success"){
		echo "<p class='success'><br />Успешно обновлено</p>";
	} elseif ($route->GET("order") == "fail") {
		echo "<p class='fail'><br />Не удалось обновить</p>";
	}
?><br />
<div class='floating'><a href='/admin/sections/add'>Добавить раздел</a></div>
<table cellpadding='0' cellspacing='0' class='list'>
	<tr class='table_header'>
		<td width='50px'>ID</td>
		<td width='270px'>Название</td>
		<td width='80px'>Порядок</td>
		<td width='50px'>Статей</td>
		<td width='150px' class='actions'>Действия</td>
	</tr><?php
		$query = "select `S`.*,count(`T`.`id`) as `tips`
					from `tip_sections` as `S`
					left join `tips` as `T`
						on `T`.`ts_id` = `S`.`id`
					group by `S`.`id`
					order by `S`.`order` desc, `S`.`id`";
		$sections = $db->getTable($query);
		foreach ($sections as $section) {

			echo "<tr><td>$section[id]</td>";
			echo "<td>{$section['name']}</td>";
			echo "<td><form method='post' action='/admin/sections/editorder/{$section['id']}'>
					<input type='text' name='order' value='{$section['order']}' style='text-align: center; width: 50px'/>
				</form></td>";
			echo "<td style='text-align: center'>{$section['tips']}</td>";
			echo "<td class='actions'><a href='/admin/sections/edit/{$section['id']}' class='edit'>Изменить</a> | <a href='/admin/sections/delete/$section[id]' class='delete'>Удалить</a></td></tr>";
		}
	?>
</table>

<?php require_once ADMIN.DS."/footer.php"; ?>